package com.newcapec.news.servlet;

import com.newcapec.news.entity.SysUser;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Description: 登录页面的展示
 * @Author: fujun
 * @Date : 2022/3/16 16:08
 * @Version : 1.0
 * @company 新开普电子股份有限公司
 */
public class ShowIndexHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            req.setCharacterEncoding("utf-8");
//            resp.setCharacterEncoding("utf-8");


        //从session对象中获取user对象

        SysUser sysUser= (SysUser) req.getSession().getAttribute("user");

            if(sysUser==null){
                //如果用户为空 ，说明用户没有登录  ，那么页面跳转到登录页面
                resp.sendRedirect("login.h?type=3");
                return;
            }


            req.getRequestDispatcher("WEB-INF/page/index.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
